<?php

App::uses('BaseLog', 'Log/Engine');
App::uses('Log', 'Model');


class DatabaseLogger extends BaseLog {

	var $Log = null;

	public function __construct($config = array()) {
		parent::__construct($config);
        // App::import('Model', 'Log');
        $this->Log = new Log();
        // App::load("Log");
	}

    public function write($type, $message) {
    	// print_r($type);die;
		// print_r($dl[$type]);die;
    	// $dl = CakeLog::defaultLevels();
		// if (in_array($dl[$type], $this->_config['types'])) {
		if (in_array($type, $this->_config['types'])) {
	        // write to the database.
            // $this->Log->set("level" , $dl[$type]);
            $this->Log->set("level" , $type);
	        $this->Log->set("dt_ins" , date('Y-m-d H:i:s'));
	        $this->Log->set("message" , $message);
			if (class_exists("CakeSession")) {
		        $this->Log->set("session" , CakeSession::id());
		        $this->Log->set("ip" , $_SERVER['REMOTE_ADDR']);
			}
			$this->Log->save();
		}
	}

}

?>